<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 获取一个 0 - 10 之间的整数
    let getRandomNum = () => {
      return Math.floor(Math.random() * 10)
    }
    let arr = []
    let sum = 0
    for (let i = 0; i < 1000; i++) {
      let num = getRandomNum()
      // 所有随机数相加
      sum += num
      // 把一千个随机数放到数组中
      arr.push(num)

    }
    // 升序排序
    arr = arr.sort((a, b) => a - b)
    // 一千个数的平均数
    let meanNumber = sum / 2

    let s1 = []
    let s2 = []
    let s1Sum = 0
    for (let i = 0; i < 1000; i++) {
      s1Sum += arr[i]
      s1.push(arr[i])
      if (s1Sum > meanNumber) {
        s2 = arr.slice(i)
        break
      }
    }
    console.log('1000随机数总和:', sum)
    console.log('s1:', s1Sum)
    console.log('s2:', sum - s1Sum)
    console.log('s1Arr:', s1)
    console.log('s2Arr:', s2)
  </script>
</body>

</html>